/******************************************************************************
 * Copyright (C) 2024 xxxx, Inc.(Gmbh) or its affiliates.
 * 
 * All Rights Reserved.
 * 
 * @file bsp_key.h
 * 
 * @par dependencies 
 * - bsp_key.h
 * - multi_button.h
 * - main.h
 * 
 * @author lange.you
 * 
 * @brief Provide the bsp key corresponding opetions.
 * 
 * Processing flow:
 * 
 * call directly.
 * 
 * @version V1.0 2024-11-10
 *
 * @note 1 tab == 4 spaces!
 * 
 *****************************************************************************/

#include "bsp_key.h"
#include "multi_button.h"
#include "main.h"

struct Button button1;

/**
 * @brief 读取按键对应GPIO的电平
 * 
 * @return uint8_t 
 */
static uint8_t read_button1_gpio(void)
{
	return HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin);
}

/**
 * @brief key init
 *
 */
void key_init(void)
{
	button_init(&button1, read_button1_gpio, 0);
	button_attach(&button1, SINGLE_CLICK, btn1_single_click_handler);
	button_start(&button1);
}

/**
 * @brief 按键单击按下处理的回调函数
 * 
 * @param btn 
 */
void btn1_single_click_handler(void *btn)
{
	if(NULL == btn)
	{
		return;
	}

	if ((Button *)btn == &button1)
	{
		led_toggle();
	}

	return;
}
